package com.qyhl.module_practice.substreet.trend;

import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeTrendBean;

import java.util.HashMap;
import java.util.List;

public class PracticeTrendModel implements PracticeTrendContract.PracticeTrendModel {
    private PracticeTrendPresenter mPresenter;

    PracticeTrendModel(PracticeTrendPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String orgId, String page, boolean isTeam) {
        String url;
        HashMap<String, String> params = new HashMap<>();
        params.put("page", page);
        if (isTeam) {
            url = PracticeUrl.GET_PRACTICE_TREND_LIST;
            params.put("orgId", orgId);
        } else {
            url = PracticeUrl.GET_PRACTICE_TREND_LIST_INS;
            params.put("insId", orgId);
        }
        EasyHttp.get(url)
                .params(params)
                .execute(new SimpleCallBack<List<PracticeTrendBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何动态！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取动态出错，请重新尝试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeTrendBean> practiceTrendBeans) {
                        if (practiceTrendBeans != null && practiceTrendBeans.size() > 0) {
                            mPresenter.setList(practiceTrendBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何动态！", !page.equals("1"));
                        }
                    }
                });
        
    }
}
